from nicegui import ui

# import userlogin
# from 考试系统.数据交互层 import layoutTools
from 考试系统.数据交互层 import logdir
from 考试系统.数据交互层 import GLOBA
#import 考试系统.数据处理层.svever as svever
from 考试系统.数据处理层 import svever
import 考试系统.数据处理层.check as check

from niceguiToolkit.layout import inject_layout_tool
# inject_layout_tool()

username=""
password=""
phone=""
yanzhen=""
yanzhen_true=""
def username_change(e):
    global username
    username=e.value
def phone_change(e):
    global phone
    phone=e.value

def password_change(e):
    global password
    password=e.value
def yanzhen_change(e):
    global yanzhen
    yanzhen=e.value

def panduan(username,phone):
    # return svever.use_number_is_in(phone) and svever.id_is_in(username)
    return True
def password_is_true(password):
    # return check.password_check(password)
    return True

def yanzhen_is_true():
    return yanzhen==yanzhen_true

def tijioa_user(username,phone,password):
    # svever.use_in(username,phone,password)
    return True
def password_is_true(password):
    global yanzhen_true
    if check.password_check(password):
        yanzhen_true=svever.yzm_out(phone)
        ui.notify("验证码以发送,不建议返回上一步;\n若需要重新发,请返回后点击下一步")
        return True
    else :
        return False

@ui.page('/注册')
def zhuce():
    GLOBA.image()
    with ui.card().classes("absolute top-1/4 inset-x-1/3 w-1/3 rounded bg-slate-300 shadow-2xl bg-white opacity-80"):
        with ui.stepper().props('vertical').classes() as stepper:
            with ui.step('请输入学工号和手机号'):
                ui.input('输入学工号',on_change=lambda e:username_change(e))
                ui.input('输入手机号',on_change=lambda e:phone_change(e))
                with ui.stepper_navigation():
                    ui.button('Next', on_click=lambda :stepper.next() if panduan(username,phone) else ui.notify('学工号或手机号已注册'))
            with ui.step('请输入密码'):
                ui.input('输入密码',on_change=lambda e:password_change(e))
                with ui.stepper_navigation():
                    # ui.button('Next', on_click=lambda :stepper.next() if password_is_true(password) else ui.notify("密码不符合要求"))
                    ui.button('Next', on_click=lambda: stepper.next())
                    ui.button('Back', on_click=stepper.previous).props('flat')

            with ui.step('请输入验证码'):
                ui.input("请输入验证码", on_change=lambda e:yanzhen_change(e))
                with ui.stepper_navigation():
                    ui.button('Next', on_click=lambda : stepper.next() if yanzhen_is_true() else ui.notify("验证码出错"))
                    ui.button('Back', on_click=stepper.previous).props('flat')
            with ui.step('Bake'):
                with ui.stepper_navigation():
                    ui.button('Done',  on_click=lambda:{tijioa_user(username,phone,password),ui.notify('注册成功!')})
                    ui.button('Back', on_click=stepper.previous).props('flat')

        with ui.row().style("flex-direction:row;width:100%;gap:0rem"):
            ui.button('返回', on_click=lambda: ui.open('/')).style("align-self:flex-start;width:100%").tailwind('mx-10 my-3')
if __name__ == '__main__':
    ui.open('/注册')